﻿<!DOCTYPE html>
<html>
<head>
	<script src="http://code.jquery.com/jquery.js" type="text/javascript"></script>
	<script src="../../jsrender.js" type="text/javascript"></script>
	<link href="../resources/demos.css" rel="stylesheet" type="text/css" />

	<link href="../resources/movielist.css" rel="stylesheet" type="text/css" />
	<style type="text/css">
		.role { font-weight: bold; font-style: italic; background-color: Yellow; }
		.synopsis { background-color: white; padding: 15px; }
		.director { font-weight: bold; font-style: italic; color: red;  }
	</style>
</head>
<body>
<a href="../demos.html">JsRender Demos</a><br />

<h3>Using {{: }} or {{> }} to render data values with optional conversion or HTML encoding</h3>

<ul>
<li>{{:value}} does not convert. Used to render values that include html markup</li>
<li>{{loc:value}} Uses custom converter.</li>
<li>{{html:value}} Converts using built-in HTML encoder. (Better security, but slight perf cost)</li>
<li>{{>value}} Alternative syntax for built-in HTML encoder.</li>
</ul><br />

<script id="movieTemplate" type="text/x-jsrender">
	<tr>
		<td>{{loc:title}}</td>
		<td class="synopsis">{{:synopsis}}</td>
		<td class="synopsis">{{>synopsis}}</td>
	</tr>
</script>

<table>
	<thead><tr><th>title</th><th>No Convert</th><th>HTML Encode</th></tr></thead>
	<tbody id="movieList"></tbody>
</table>

<script type="text/javascript">

	var movies = [
		{
			title: "Meet Joe Black",
			synopsis: "The <span class='role'>grim reaper</span> (<a href='http://www.netflix.com/RoleDisplay/Brad_Pitt/73919'>Brad Pitt</a>) visits <span class='role'>Bill Parrish</span> (<a href='http://www.netflix.com/RoleDisplay/Anthony_Hopkins/43014'>Anthony Hopkins</a>)..."
		},
		{
			title: "Eyes Wide Shut",
			synopsis: "Director <span class='director'>Stanley Kubrick's</span> final film: <br/><br/><img src='http://cdn-4.nflximg.com/US/boxshots/large/5670434.jpg'/>"
		}
	];

	$.views.converters({
		loc: function (value) {
			switch (value) {
				case "Meet Joe Black":
					return "Rencontrez Joe Black";
					break;

				case "Eyes Wide Shut":
					return "Les Yeux Grand Fermés";
					break;

				default:
					return value||"";
			}
		}
	});
	$( "#movieList" ).html(
		$( "#movieTemplate" ).render( movies )
	);

</script>

</body>
</html>
